// mock/user.js
export default [
  {
    url: '/mock/api/login',
    method: 'post',
    response: ({ body }) => {
      if (body.username === 'admin' && body.password === '123456') {
        return {
          code: 200,
          message: 'success',
          data: {
            token: 'fake-jwt-token',
            username: 'admin',
            roles: ['admin']
          },
          headers: {
            // 示例：设置 Set-Cookie（注意：本地 mock 环境下浏览器可能不会真正设置 Cookie，仅用于调试）
            'Set-Cookie': 'authToken=fake-jwt-token; Path=/; SameSite=Lax'

          }
        };
      }
      return {
        code: 401,
        message: '用户名或密码错误'
      };
    }
  },
  {
    url: '/mock/api/user/info',
    method: 'get',
    response: () => ({
      code: 200,
      data: {
        name: '张三',
        age: 30,
        avatar: 'https://example.com/avatar.jpg'
      }
    })
  },
  {
    url: '/mock/api/user/logout',
    method: 'post',
    response: () => ({
      code: 200,
      message: 'success'
    })
  },
  {
    url: '/mock/api/user/roles',
    method: 'get',
    response: () => ({
      code: 200,
      data: ['admin', 'editor']
    })
  },
  {
    url: '/mock/api/user/authButton',
    method: 'get',
    response: () => ({
      code: 200,
      data: ['page3:view', 'page3:edit']
    })
  },
  {
    url: '/mock/api/user/authTree',
    method: 'get',
    response: () => ({
      code: 200,
      data: [
        { path: "page3", name: "菜单项3", component: "Page3", icon: "UserOutlined" },
        { path: "page4", name: "菜单项4", component: "Page4", icon: "CheckCircleOutlined" },
        {
          path: "sys-setting",
          name: "系统设置",
          icon: "SettingOutlined",
          children: [
            { path: "page5", name: "菜单项5", component: "Page5", icon: "FormatPainterOutlined" },
            { path: "page6", name: "菜单项6", component: "Page6", icon: "CalendarOutlined" }
          ]
        },
        { path: "page7", name: "菜单项7", component: "Page7", icon: "FileTextOutlined" },
        { path: "page8",
          name: "菜单项8",  
          icon: "FileTextOutlined",
          external: true,
          url: "https://www.baidu.com" },
      ]
    })
  }
];